//
//  HFNetWorkTools.swift
//  HFWeChat
//
//  Created by 黄来峰 on 16/4/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import AFNetworking
//请求方式的枚举
enum HFRequestMethod: Int{
    case GET = 0
    case POST = 1
}
class HFNetWorkTools: AFHTTPSessionManager {
     //MARK: - 定义一个网络请求管理的单例类
    static let sharedTools: HFNetWorkTools = {
    
        let tools = HFNetWorkTools()
        
        tools.responseSerializer.acceptableContentTypes?.insert("text/plain")
//        tools.responseSerializer =
        return tools
   
    }()
    
    //定义一个网络请求管理类
    func request(method: HFRequestMethod,urlString: String,params:AnyObject?,callBack:(response:AnyObject?,error:NSError?)->()){
        if method == .GET{
            self.GET(urlString, parameters: params, progress: nil, success: { (_, response) -> Void in
                callBack(response: response, error: nil)
      
                }, failure: { (_, error) -> Void in
                    
                callBack(response: nil, error: error)
            })   
        
        } else {
            
            self.POST(urlString, parameters: params, progress: nil, success: { (_, response) -> Void in
                
                callBack(response: response, error: nil)
         
                }, failure: { (_, error) -> Void in
                    
                callBack(response: nil, error: error)
            })
        }
    }
    
       
}
